<%--
  Created by IntelliJ IDEA.
  User: CMCC
  Date: 2016/8/30
  Time: 16:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/contractInfo.css"/>
    <link rel="stylesheet" href="css/pagination.css"/>
    <script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript" src="js/handlebars-v3.0.3.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/mui.min.js"></script>
    <script type="text/javascript" src="js/pagination.js"></script>
    <script type="text/javascript">
        var hosturl = "http://"+ window.location.host + "/"+ window.location.pathname.split('/')[1];
        var adminSessionID = <%=session.getAttribute("SID")%>;
        var adminSessionName = "<%=session.getAttribute("SName")%>";
        if (adminSessionID === null) {
            window.location.href = "login.jsp";
        } else {
        }
    </script>
    <script type="text/javascript">
        window.onload = function () {
            var oUserInfo = document.getElementById('userInfo');
            var ocCntractInfo = document.getElementById('contractInfo');
            var oLogInfo = document.getElementById('logInfo');
            document.getElementById("adminName").innerHTML = " " + adminSessionName + " ";
            oUserInfo.onmousedown = function () {
                ocCntractInfo.style.backgroundColor = "#fff";
                ocCntractInfo.style.color = "#000";
                oUserInfo.style.backgroundColor = "#324e75";
                oUserInfo.style.color = "#fff";
            };
            ocCntractInfo.onmousedown = function () {
                oUserInfo.style.backgroundColor = "#fff";
                oUserInfo.style.color = "#000";
                ocCntractInfo.style.backgroundColor = "#324e75";
                ocCntractInfo.style.color = "#fff";
            }
            ocCntractInfo.onclick = function () {
                window.location.href = hosturl+'/contractMana.jsp';
            };
            oUserInfo.onclick = function () {
                window.location.href = hosturl+'/userMana.jsp';
            };
            //添加合同信息

            //注销
            var oLogout = document.getElementById('logout');
            oLogout.onclick = function () {
                mui.ajax(hosturl+"/admin/logout", {
                    data: {
//                    "contractId": 1
                    },
                    dataType: "json",
                    type: "get",
                    timeout: 10000,
                    success: function(data) {
                        alert(data.description)
                        window.location.href = 'login.jsp';

                    },
                    error: function(xhr, type, errorThrown) {
                        console.log(type);
                    }
                });
            };
        }
    </script>
    <script type="text/javascript">
        mui.ready(function () {
            mui.ajax(hosturl+"/log/searchByAdmin", {
                data: {
//                    "contractId": 1
                },
                dataType: "json",
                type: "post",
                timeout: 10000,
                success: function(data) {
                    document.getElementById("dataLen").innerHTML="共有"+data.body.length +"条";
                    $('#pagination-container').pagination({
                        dataSource: data.body,
                        pageSize: 5,
                        showGoInput: true,
                        showGoButton: true,
                        autoHidePrevious: true,
                        autoHideNext: true,
//                        showPrevious: false,
//                        showNext: false,
//                        showPageNumbers: false,
//                        showNavigator: true,
                        pageNumber: 1,
                        callback: function (data, pagination) {
                            // template method of yourself
                            var html = simpleTemplating(data);
                            $('#data-container').html(html);
                        }
                    });

                },
                error: function (xhr, type, errorThrown) {
                    console.log(type);
                }
            });
        });
    </script>
    <title>日志信息</title>
</head>

<body>
<div class="top">
    <div class="top-left">
        <p class="top-left">合同管理系统</p>
    </div>
    <div class="top-right">
        <p class="p1">欢迎管理员<span class="" id="adminName"> 张三 </span>的到来 <a href="#" id="logout">注销 </a></p>
    </div>
</div>
<div class="left-block">
    <ul>
        <li id="contractInfo" class="uleft-index">合同管理</li>
        <li id="userInfo" class="uleft-index">用户管理</li>
        <li id="logInfo" class="cleft-index">日志管理</li>
    </ul>
</div>
<div class="main-part">
    <ul>
        <li class="right-label">日志信息</li>
        <!--<li class=""><input class="right-btn" type="button" value="修改合同信息" /></li>-->
        <!--<li class=""><input class="right-btn" type="button" value="搜索" /></li>-->
        <li class="full-width"></li>
        <li class="">
            <div class="row">
                <div class="col-lg-4">
                    <div class="input-group">
                        <span class="input-group-addon" id="basic-addon1">用户名</span>
                        <input id="uId" type="text" class="form-control" placeholder="用户名"
                               aria-describedby="basic-addon1">
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="input-group">
                        <span class="input-group-addon" id="basic-addon2">用户IP</span>
                        <input id="uIP" type="text" class="form-control" placeholder="用户IP"
                               aria-describedby="basic-addon1">
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="input-group">
                        <span class="input-group-addon" id="basic-addon3">行为</span>
                        <input id="uOper" type="text" class="form-control" placeholder="操作行为"
                               aria-describedby="basic-addon1">
                    </div>
                </div>

                <div class="col-lg-8">
                    <div class="input-group">
                        <span class="input-group-addon" id="basic-addon5">操作时间</span>
                        <input id="oSTime" type="date" class="form-control" placeholder="开始时间"
                               aria-describedby="basic-addon1">
                        <input id="oETime" type="date" class="form-control" placeholder="结束时间"
                               aria-describedby="basic-addon1">
                    </div>
                </div>
                <div class="col-lg-4">
                    <button id="search" onclick="searchLog()" type="button" class="btn btn-primary">搜索</button><br />
                    <label id="dataLen">共有？条</label>
                </div>
            </div>
        </li>
        <li>
            <table id="table1" class="table table-bordered table-striped table-hover">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>用户名</th>
                    <%--<th>用户</th>--%>
                    <th>IP</th>
                    <th>操作时间</th>
                    <th>用户类型</th>
                    <th>操作类型</th>
                    <%--<th></th>--%>
                </tr>
                </thead>
                <tbody id="data-container">
                </tbody>

                </tbody>
            </table>
            <div id="wrapper">
                <section>
                    <div id="pagination-container"></div>
                </section>
            </div>
        </li>
    </ul>
</div>
</body>
<script type="text/javascript">

    //处理分页数据
    function simpleTemplating(data) {
        var html = '';
        $.each(data, function (index, item) {
            var newDate = new Date();
            newDate.setTime(item.functionTime);
            html += '<tr>';
            html += '<td>' + item.id + '</td>';
//            html += '<td>'+ item.userId +'</td>';
            html += '<td>' + item.userName + '</td>';
            html += '<td>' + item.ip + '</td>';
            html += '<td>' + newDate.toLocaleDateString() + '</td>';
            html += '<td>' + item.domain + '</td>';
            html += '<td>' + item.operation + '</td>';
//            html +=  '<td><a href="javascript:update(123,123);">修改</a>&nbsp;&nbsp;&nbsp;<a href="javascript:update(123,123);">删除</a></td>';
            html += '</tr>';
        });
        return html;

    }

    function searchLog() {
        var userName = $("#uId").val();
        var uIP = $("#uIP").val();
        var uOper = $("#uOper").val();
        var oSTime = $('#oSTime').val();
        var oETime = $('#oETime').val();

        mui.ajax(hosturl+"/log/searchReqByAdmin", {
            data: {
                "userName": userName,
                "IP": uIP,
                "Oper": uOper,
                "timeS": oSTime,
                "timeE": oETime
            },
            dataType: "json",
            type: "post",
            timeout: 10000,
            success: function (data) {
                if (data.status == "datanull") {
                    $('#data-container').html("");
                    $('#pagination-container').html("");


                    document.getElementById("dataLen").innerHTML="共有0条";
                }else {
                    document.getElementById("dataLen").innerHTML="共有"+data.body.length +"条";

                    $('#pagination-container').pagination({
                        dataSource: data.body,
                        pageSize: 5,
                        showGoInput: true,
                        showGoButton: true,
                        autoHidePrevious: true,
                        autoHideNext: true,
//                        showPrevious: false,
//                        showNext: false,
//                        showPageNumbers: false,
//                        showNavigator: true,
                        pageNumber: 1,
                        callback: function (data, pagination) {
                            // template method of yourself
                            var html = simpleTemplating(data);
                            $('#data-container').html(html);
                        }
                    });
                }

            },
            error: function (xhr, type, errorThrown) {
                console.log(type);
            }
        });
    }
</script>
</html>
